﻿using AF_Application.Interface.App;
using AF_Application.Interface.Cache;
using AF_DataModel;
using AF_IOC;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;


namespace WebApp_Standard.H_Action
{
    /// <summary>
    /// H_Action 的摘要说明
    /// </summary>
    public class H_Action : IHttpHandler
    {

        IAppImpl App = IOC.Instance.Get<IAppImpl>();
        ISessionCacheProvider SessionCacheProvider = IOC.Instance.Get<ISessionCacheProvider>();
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (context.Request.QueryString["action"] != null)
            {
                switch (context.Request.QueryString["action"].ToString())
                {
                    case "UPUser":
                        UPUser(context);
                        break;
                    default:
                        break;
                }
            }
        }

        private void UPUser(HttpContext context)
        {

            string OpenId = "";
            string msg = "";
            int score = int.Parse(context.Request.Form["score"].ToString());
            if (SessionCacheProvider.Get<string>("OpenId") != null)
            {
                OpenId = SessionCacheProvider.Get<string>("OpenId").ToString();
                T_User user = App.GetUserByOpenID(OpenId);
                if (user != null)
                {
                    user.Score = score;
                    user.PlayNum = user.PlayNum + 1;
                }

                App.UPUser(user);

                //记录每一次

                //T_Act act = new T_Act();
                //act.Id = Guid.NewGuid();
                //act.OpenID = OpenId;
                //act.Score = score;
                //act.CreateTime = DateTime.Now;
                //App.AddAct(act);




                msg = "1";
            }
            context.Response.Write(msg);


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}